/**
 * @Author：ming
 * @Date：2023/10/4 8:55 PM
 * @Filename：Lc5
 */

/**
 * @author ming
 */
public class Lc5 {
    public String longestPalindrome(String s) {
        //有中心的回文子串
        int l = 0;
        int r =0;
        int len = s.length();
        String a = new String();
        for (int i = 0; i < len; i++) {
            l = i;
            r=i;
            while (l>=0&&r<len&&s.charAt(l)==s.charAt(r)){
                l--;r++;

            }
            String temp = s.substring(l+1,r);
            if(temp.length()>a.length()){
                a = temp;
            }
        }

        //无中心的

        String b = new String();
        for (int i = 0; i < len-1; i++) {
            l =i;
            r=i+1;
            while (l>=0&&r<len&&s.charAt(l)==s.charAt(r)){
                l--;r++;
            }
            String temp = s.substring(l+1,r);
            if(temp.length()>b.length()){
                b = temp;

            }
        }

        if(a.length()>b.length()){
            return a;
        }else {
            return b;
        }

    }
}
